﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace ET.Monitor.DAL
{

    public class CountryDAL
    {
        string strSql = "", strErrMsg = "";
        object obj = null;
        DataTable dt = new DataTable();

        InvokeWebService iw = new InvokeWebService();
        string rtdbRelationAddress = "";
        string rtdbRealTimeAddress = "";
        string rtdbNameSpace = "";

        public CountryDAL()
        {
            rtdbRelationAddress = ConfigurationManager.ConnectionStrings["RelationURL"].ConnectionString;
            rtdbRealTimeAddress = ConfigurationManager.ConnectionStrings["RealTimeURL"].ConnectionString;
            rtdbNameSpace = ConfigurationManager.ConnectionStrings["NameSpace"].ConnectionString;
        }

        #region 区域国家
        public DataTable GetCountry()
        {
            strSql = "";
            strSql = "select *from T_BASE_NATION";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        #endregion

        #region 节假日
        public DataTable GetHoliday(string id, DateTime st, DateTime et)
        {
            strSql = "";
            strSql = "select *from T_INFO_HOLIDAY where  T_DATE between '" + st + "' and '" + et + "'";
            dt = (DataTable)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunDataTable", new object[] { strSql, strErrMsg });
            return dt;
        }
        public bool AddHolidays(string year, string holidayList)
        {
            strSql = "DELETE FROM T_INFO_HOLIDAY WHERE  CONVERT(VARCHAR(50),T_DATE,120) LIKE '" + year + "%';";
            if (!string.IsNullOrEmpty(holidayList))
            {
                string[] arr = holidayList.Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    strSql += "INSERT INTO T_INFO_HOLIDAY VALUES('" + arr[i] + "','');";
                }
            }
            return (bool)iw.RunWebService(rtdbRelationAddress, rtdbNameSpace, "RunNonQuery", new object[] { strSql, strErrMsg });
        }
        #endregion



    }
}
